<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../css/style.css">
	<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../plugins/bootstrap/js/bootstrap.min.js"></script>

</head>

<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
	<div class="box-header with-border">
		<h3 class="box-title">商品审核</h3>
	</div>

	<div class="box-body">

		<!-- 数据表格 -->
		<div class="table-box">

			<!--工具栏-->
			<div class="pull-left">
				<div class="form-group form-inline">
					<div class="btn-group">
						<button type="button" onclick="deleteBatch()" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
						<button type="button" onclick="SubmitReview(2)" class="btn btn-default" title="审核通过" ><i class="fa fa-check"></i> 审核通过</button>
						<button type="button" onclick="SubmitReview(3)" class="btn btn-default" title="驳回" ><i class="fa fa-ban"></i> 驳回</button>
						<button type="button" class="btn btn-default" title="刷新" ><i class="fa fa-refresh"></i> 刷新</button>
					</div>
				</div>
			</div>
			<div class="box-tools pull-right">
				<div class="has-feedback">
					商品名称：<input id="goodsName">
					<button class="btn btn-default" onclick="getGoods()">查询</button>
				</div>
			</div>
			<!--工具栏/-->

			  <!--数据列表-->
			  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
				  <thead>
					  <tr>
						  <th class="" style="padding-right:0px">
							  <input id="selall" type="checkbox" class="icheckbox_square-blue">
						  </th>
						  <th class="sorting_asc">商品ID</th>
						  <th class="sorting">商品名称</th>
						  <th class="sorting">商品价格</th>
						  <th class="sorting">一级分类</th>
						  <th class="sorting">二级分类</th>
						  <th class="sorting">三级分类</th>
						  <th class="sorting">状态</th>
						  <th class="text-center">操作</th>
					  </tr>
				  </thead>
				  <tbody id="goodsInfo">

				  </tbody>
			  </table>
			  <!--数据列表/-->
		</div>
		<!-- 数据表格 /-->
	 </div>
	<!-- /.box-body -->

  <!-- 编辑窗口 -->
  <div class="modal fade" id="insertEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	  <div class="modal-dialog" >
		  <div class="modal-content">
			  <div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				  <h3 id="myModalLabel">商品详细</h3>
			  </div>
			  <div class="modal-body">
				  <!-- 正文区域 -->
				  <section class="content">
					  <div class="box-body">
						  <!--tab页-->
						  <div class="nav-tabs-custom">
							  <!--tab头-->
							  <ul class="nav nav-tabs">
								  <li class="active">
									  <a href="#home" data-toggle="tab">商品基本信息</a>
								  </li>
								  <li >
									  <a href="#pic_upload" data-toggle="tab">商品图片</a>
								  </li>
								  <li >
									  <a href="#customAttribute" data-toggle="tab">扩展属性</a>
								  </li>
								  <li >
									  <a href="#spec" data-toggle="tab" >规格</a>
								  </li>
							  </ul>
							  <!--tab头/-->

							  <!--tab内容-->
							  <div class="tab-content">

								  <!--表单内容-->
								  <div class="tab-pane active" id="home">
									  <div class="row data-type">
										  <!--<div class="col-md-2 title">商品分类</div>

										  <div class="col-md-10 data">
											  <table>
												  <tr>
													  <td>
														  <select class="form-control" >
														  </select>
													  </td>
													  <td>
														  <select class="form-control select-sm" ></select>
													  </td>
													  <td>
														  <select class="form-control select-sm" ></select>
													  </td>
													  <td>
														  模板ID:19
													  </td>
												  </tr>
											  </table>

										  </div>-->


										  <div class="col-md-2 title">商品名称</div>
										  <div class="col-md-10 data">
											  <input type="text" id="goodName" class="form-control"    placeholder="商品名称" value="">
										  </div>

										  <div class="col-md-2 title">品牌</div>
										  <div class="col-md-10 data">
											  <input type="text" id="brand" class="form-control">
										  </div>

										  <div class="col-md-2 title">副标题</div>
										  <div class="col-md-10 data">
											  <input type="text" id="caption" class="form-control"   placeholder="副标题" value="">
										  </div>

										  <div class="col-md-2 title">价格</div>
										  <div class="col-md-10 data">
											  <div class="input-group">
												  <span class="input-group-addon">¥</span>
												  <input type="text" id="price" class="form-control"  placeholder="价格" value="">
											  </div>
										  </div>

										  <div class="col-md-2 title editer">商品介绍</div>
										  <div class="col-md-10 data editer">
											  <!--<textarea  name="content" style="width:800px;height:400px;visibility:hidden;" ></textarea>-->
											  <span id="introduction"></span>
											  <!--<input type="text" id="introduction" class="form-control">-->
										  </div>

										  <div class="col-md-2 title rowHeight2x">包装列表</div>
										  <div class="col-md-10 data rowHeight2x">
											  <!--<input type="text" id="packageList" class="form-control">-->
											  <span id="packageList"></span>
										  </div>

										  <div class="col-md-2 title rowHeight2x">售后服务</div>
										  <div class="col-md-10 data rowHeight2x">
											  <span id="saleService"></span>
										  </div>


									  </div>
								  </div>

								  <!--图片上传-->
								  <div class="tab-pane" id="pic_upload">
									  <div class="row data-type">
										  <table class="table table-bordered table-striped table-hover dataTable">
											  <thead>
											  <tr>
												  <th class="sorting">颜色</th>
												  <th class="sorting">图片</th>
											  </thead>
											  <tbody id="imgs">

											  </tbody>
										  </table>

									  </div>
								  </div>


								  <!--扩展属性-->
								  <div class="tab-pane" id="customAttribute">
									  <div class="row data-type" id="customss">

									  </div>
								  </div>

								  <!--规格-->
								  <div class="tab-pane" id="spec">
									  <p>

									  <div>

										  <div class="row data-type" id="specpj">

										  </div>


										  <div class="row data-type">
											  <table class="table table-bordered table-striped table-hover dataTable">
												  <thead>
												  <tr>
													  <th class="sorting">屏幕尺寸</th>
													  <th class="sorting">网络制式</th>
													  <th class="sorting">价格</th>
													  <th class="sorting">库存</th>
												  </tr>
												  </thead>
												  <tbody id="speccss">

												  </tbody>
											  </table>

										  </div>

									  </div>
								  </div>

							  </div>
							  <!--tab内容/-->
							  <!--表单内容/-->
						  </div>
					  </div>

				  </section>
				  <div class="modal-footer">
					  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
				  </div>
			  </div>
		  </div>
	  </div>


	  <!-- 正文区域 /-->
	  <script type="text/javascript">
		  var editor;
		  KindEditor.ready(function(K) {
			  editor = K.create('textarea[name="content"]', {
				  allowFileManager : true
			  });
		  });
	  </script>

	  <div class="modal-footer">
		  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
	  </div>
  </div>
  </div>
  </div>
        
</body>
<script>
	$(function () {
		getGoods();
	})
	function getGoods() {
		$.ajax({
			url : "/goodsController/getGoodsInfo",
			type : "post",
			data : {goodsName:$("#goodsName").val()},
			dataType : "json",
			async : false,
			success : function(result){
				if(result.code == 200){
					var goodsInfo = result.data;
					var html = "";
					$(goodsInfo).each(function(i,e){
						html += '<tr><td><input  type="checkbox" value="'+e["id"]+'"></td><td>'+e["id"]+'</td><td>'+e["goodsName"]+'</td><td>'+e["price"]+'</td><td>'+e["category1Ids"]+'</td><td>'+e["category2Ids"]+'</td><td>'+e["category3Ids"]+'</td>';
						if (e['auditStatus'] == 0){
							html+= '<td>未申请</td>';
						}else if (e['auditStatus'] == 1){
							html+= '<td style="color: #00acd6">申请中</td>';
						}else if (e['auditStatus'] == 2){
							html+= '<td style="color: #00a65a">审核通过</td>';
						}else{
							html+= '<td style="color: red">已驳回</td>';
						}
						html +='<td class="text-center"><button type="button" class="btn bg-olive btn-xs"  onclick="showdetails('+e["id"]+')" data-toggle="modal" data-target="#insertEditModal">详情</button></td></tr>';
					})
					$("#goodsInfo").html(html);
				}
			},
			error :function(result){
				alert(result.message);
			}
		})
	}

	//详情展示
	function showdetails(id) {
		$.ajax({
			url:"/goodsController/getDetailsById",
			type:"post",
			data:{id:id},
			dataType:"json",
			async:true,
			success:function (result) {
				if (result.code == 200){
					var details = result.data;
					console.log(details)

					$("#goodName").val(details[0].goodsName);
					$("#brand").val(details[0].brand);
					$("#caption").val(details[0].caption);
					$("#price").val(details[0].price);
					$("#introduction").text(details[0].introduction);
					$("#packageList").text(details[0].packageList);
					$("#saleService").text(details[0].saleService);

					//商品图片
					var itemImage = JSON.parse(details[0].itemImages);
					var image = "";
					for (var i = 0; i < itemImage.length; i++) {
						image +='<tr><td><input value="'+itemImage[i].color+'"></td><td><img src="'+itemImage[i].url+'" width="100px" height="100px"></td></tr>';
					}
					$("#imgs").html(image);
					//扩展属性
					//字符串转对象
					var customIds =JSON.parse(details[0].customAttributeItems);
					var html = "";
					$(customIds).each(function(i,e){
						html += '<div><div class="col-md-2 title">'+e["text"]+'</div><div class="col-md-10 data"><input value="'+e["value"]+'" class="form-control" placeholder="'+e["text"]+'"></div></div>';
					})
					$("#customss").html(html);
					//规格
					var specificationItem =JSON.parse(details[0].specificationItems);
					var html = "";
					/*<input type="hidden" value="'+e["id"]+'">*/
					$(specificationItem).each(function(i,e){
						html += '<div><div class="col-md-2 title">'+e["attributeName"]+'</div><div class="col-md-10 data" id="'+e["id"]+'">';
						html += e["attributeValue"];
						html += '</div></div>';
					})
					$("#specpj").html(html);
					//规格选项
					var html3 = "";
					for (var i = 0; i < details.length; i++) {
						var spe =JSON.parse(details[i].spec);
						html3 += '<tr><td>'+spe.屏幕尺寸+'</td><td>'+spe.网络制式+'</td>';
						html3 += '<td><input class="form-control"  value="'+details[i].p+'" placeholder="价格"></td>';
						html3 += '<td><input class="form-control" value="'+details[i].num+'" placeholder="库存数量"></td></tr>';
					}
					$("#speccss").html(html3);

				}
			},
			error:function(result){
				alert(result.message);
			}
		})
	}

	//删除
	function deleteBatch() {
		var ids = [];
		var boxs = $("[type=checkbox]:checked");
		for (var i = 0; i < boxs.length; i++) {
			ids.push(boxs[i].value);
		}
		alert(ids);
		if(ids.length <= 0){
			toastr.error("请选择需要删除的数据");
			return;
		}
		if (confirm("是否确认删除?")){
			$.ajax({
				url:"/goodsController/deleteBatch",
				type:"post",
				data:{ids:ids},
				dataType:"json",
				async:true,
				success:function (result) {
					if (result.code == 200){
						alert(result.message);
						window.location.reload();
					}
				},
				error:function(result){
					alert(result.message);
				}
			})
		}
	}
	//审核通过
	function SubmitReview(statu) {
		var ids = [];
		var boxs = $("[type=checkbox]:checked");
		for (var i = 0; i < boxs.length; i++) {
			ids.push(boxs[i].value);
		}
		alert(ids);
		if(ids.length <= 0){
			alert("请选择的数据");
			return;
		}
		if (confirm("是否确认?")){
			$.ajax({
				url:"/goodsController/SubmitReview",
				type:"post",
				data:{ids:ids,statu:statu},
				dataType:"json",
				async:true,
				success:function (result) {
					if (result.code == 200){
						alert(result.message);
						window.location.reload();
					}
				},
				error:function(result){
					alert(result.message);
				}
			})
		}
	}
</script>

</html>